# Use a lightweight JRE (not JDK) for production
FROM eclipse-temurin:21-jre-jammy

# Set the working directory (consistent with Java conventions)
WORKDIR /app

# Copy ONLY the JAR file (faster builds, smaller layers)
COPY build/libs/product-service-0.0.1-SNAPSHOT.jar product-service.jar

# Set JVM options (best practices for containers)
ENV JAVA_OPTS="-server -XX:MaxRAMPercentage=75.0 -XX:+UseContainerSupport -XX:+ExitOnOutOfMemoryError"

# Default Spring profile (override with `-e SPRING_PROFILES_ACTIVE=dev` at runtime)
ENV SPRING_PROFILES_ACTIVE=prod

# Run as non-root user (security best practice)
RUN adduser --system --group appuser && chown -R appuser:appuser /app
USER appuser

# Expose port (documentation only; actual mapping is done via `docker run -p`)
EXPOSE 8080

# Use shell-less ENTRYPOINT for better signal handling
ENTRYPOINT ["java", "-jar", "product-service.jar"]